/* 
 * Copyright (C) 2012 Martin Řehánek <Martin.Rehanek at mzk.cz>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


goog.provide('kramerius.audio.ui.VolumeSlider');

goog.require('kramerius.audio.ui.PlayerComponent');
goog.require('goog.ui.Slider');


/**
 * @constructor 
 * @param {Element} container Element containing this component.
 * @param {kramerius.audio.Controller} controller Controller of the audio player.
 * @param {boolean} loggingEnabled whether logging should be enabled (for debugging)
 */
kramerius.audio.ui.VolumeSlider = function(container, controller, loggingEnabled){
    kramerius.audio.ui.PlayerComponent.call(this, container, controller);
    /** @private */
    this.loggingEnabled_ = loggingEnabled;
    /** @private */
    this.slider_ = this.initSlider_();
    this.controller_.setVolumeSlider(this);
    //this.setPosition(13);
    this.enable();
};
goog.inherits(kramerius.audio.ui.VolumeSlider, kramerius.audio.ui.PlayerComponent);


/** @private **/
kramerius.audio.ui.VolumeSlider.prototype.initSlider_ = function(){
    this.log_("initializing slider");
    var slider =  new goog.ui.Slider();
    //slider.decorate(this.container);
    slider.setOrientation(goog.ui.Slider.Orientation.HORIZONTAL);
    slider.setMoveToPointEnabled(true);
    var volumeSlider = this;
    var controller = this.controller_;
    slider.addEventListener(goog.ui.Component.EventType.CHANGE, function() {
        // TODO: OPRAVIT. tahle zmena znamena i to, ze je mute
        // a tak controller zmeni tuhle hodnotu a zpet se nastavi 
        // 0 controllerovi
        //console.log("volume slider CHANGED to position: " + slider.getValue());
        controller.setVolume(slider.getValue());
    });
    //slider.setValue(volumeLevel);
    //slider.setValueAndExtent(30);
    slider.createDom();
    slider.render(this.container_);
    var sliderEl = slider.getElement();
    new goog.ui.Tooltip(slider.getElement(), "nastavit hlasitost");
    //
    //tady resim to, ze se volume slider nenastavuje na defaultni hodnotu
    //ale vzdy na 0
    //z nejakeho duvodu se nechyta nastaveni pres setValue()
    //slider.getValueThumb().style.left='95px';
    return slider;
};


kramerius.audio.ui.VolumeSlider.prototype.enable = function(){
    this.slider_.setEnabled(true);
};

/**
 * @param {number} position
 */
kramerius.audio.ui.VolumeSlider.prototype.setPosition = function(position){
    //console.log("setting slider position to " + position);
    this.slider_.setValue(position);
};


//kramerius.audio.ui.VolumeSlider.prototype.disable = function(){
//    this.slider_.setEnabled(false);
//};


//public
//kramerius.audio.ui.VolumeSlider.prototype.show = function(){
//    this.slider_.setVisible(true);
//}

//public
//kramerius.audio.ui.VolumeSlider.prototype.hide = function(){
//    this.slider_.setVisible(false);
//}


/** @private */
kramerius.audio.ui.VolumeSlider.prototype.log_= function(text){
    if(this.loggingEnabled_){
        console.log("VOLUME SLIDER: " + text);
    }
}


